package com.ylr.send.framework.controller.api;

import com.ylr.send.framework.manager.SmsManager;
import com.ylr.send.common.dto.SendSmsDto;
import com.ylr.base.common.tool.Result;
import com.ylr.send.common.vo.BatchSendSmsVo;
import com.ylr.send.common.vo.SendSmsVo;
import com.ylr.send.framework.feign.SmsBaseClient;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-06-15 15:41:09
 * className: SmsApiController
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("/api/sms")
@AllArgsConstructor
public class SmsApiController implements SmsBaseClient {

    private static final Logger log = LoggerFactory.getLogger(SmsApiController.class);

    private final SmsManager smsManager;

    /**
     * 发送短信接口
     * @param sendSmsVo 参数对象
     * @return 发送结果
     */
    @PostMapping("/send")
    public Result<SendSmsDto> sendSms(@Validated @RequestBody SendSmsVo sendSmsVo) {
        log.info("api => 开始发送短信操作。{}", sendSmsVo);

        SendSmsDto sendSmsDto = smsManager.sendSms(sendSmsVo);

        log.info("api => 发送短信操作结束。{}", sendSmsDto);
        return Result.success(sendSmsDto);
    }

    /**
     * 批量发送短信接口
     * @param batchSendSmsVo 参数对象
     * @return 发送结果
     */
    @PostMapping("/batch/send")
    public Result<SendSmsDto> batchSendSms(@Validated @RequestBody BatchSendSmsVo batchSendSmsVo) {
        log.info("api => 开始批量发送短信操作。{}", batchSendSmsVo);

        SendSmsDto sendSmsDto = smsManager.batchSendSms(batchSendSmsVo);

        log.info("api => 批量发送短信操作结束。{}", sendSmsDto);
        return Result.success();
    }
}
